package student.aistar.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import student.aistar.mapper.ItemCFMapper;
import student.aistar.model.entity.Collect;
import student.aistar.model.entity.Product;
import student.aistar.service.ItemCFService;
import student.aistar.util.ItemCFUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Auther: zhugefeng
 * @Date:2021/10/24 23:49
 **/
@Service
@Transactional
public class ItemCFServiceImpl implements ItemCFService {
    @Autowired
    private ItemCFMapper itemCFMapper;

    @Override

    public ArrayList<Integer> result(Integer userId) {
        ItemCFUtil itemCFUtil = new ItemCFUtil();
        List<Collect> list = new ArrayList<>();
        list = itemCFMapper.findCollectByUser(userId);
        if (list.size() == 0 || list == null) {
            System.out.println("sss");
            return null;
        }
        Integer count = itemCFMapper.findCollectCount();
        return itemCFUtil.results(userId, itemCFMapper.findAllCollects(), count);
    }

    @Override
    public List<Product> recommend(ArrayList<Integer> productId) {
        List<Product> products = new ArrayList<>();
        for (Integer integer : productId) {
            products.add(itemCFMapper.findByProductId(integer));
        }
        return products;
    }
}
